package com.example.database.demo.controller;

import com.example.database.demo.pojo.JewelryPojo.requestData.Cancellnsure.CancellnsureParam;
import com.example.database.demo.pojo.JewelryPojo.requestData.Insure.InsureParam;
import com.example.database.demo.pojo.JewelryPojo.responseData.ResponseData;
import com.example.database.demo.service.JewelryCargoInsuranceService;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import java.util.List;

/**
 * @author xionglin
 */
@RestController
public class JewelryCargoInsuranceController {
    @Autowired
    private JewelryCargoInsuranceService insuranceService;

    /**
     * 投保接口
     */
    @RequestMapping(value = "/doInsure", method = RequestMethod.POST)
    public List<ResponseData> doInsure(@RequestBody @Validated List<InsureParam> insureParamList) throws IOException, NoSuchAlgorithmException, InvalidKeySpecException {
        return insuranceService.doInsure(insureParamList);
    }

    /**
     * 退保接口
     */
    @RequestMapping(value = "/cancelInsure", method = RequestMethod.POST)
    public ResponseData cancelInsure(@RequestBody @Validated CancellnsureParam cancellnsureParam) throws NoSuchAlgorithmException, InvalidKeySpecException, JsonProcessingException {
        return insuranceService.doCancelInsure(cancellnsureParam);
    }
}
